const arr = [1, 2, 3, 4, 2, 1]

function unique(arr) {
  let newArr = []
  for (let i = 0; i < arr.length; i++) {
    // if (newArr.indexOf(arr[i]) === -1) newArr.push(arr[i])//时间复杂度O(n^2)因为indexOf会再循环一遍
    if (!newArr.includes(arr[i])) newArr.push(arr[i])//存在的话返回true，否则返回false
  }
  return newArr
}
